package com.itfenghuang.day18;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/*
      会话域
 */
public class A06_Session extends HttpServlet {
/*
域:范围
    域对象:不同作用范围的区域   在这个区域中,可以进行数据共享
    再一次会话中共享数据
 */

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        获取会话域对象
        HttpSession session = req.getSession();
//        向会话域中存储一条数据
        Object username = session.getAttribute("username");
        System.out.println(username);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}


